(function(global){            
    var JSON_Util = {};
    
    /**
     * 确保指定的参数是一个JSON；若不是，则转换成JSON。
     */
    JSON_Util.insure = function(json){
        return ujs.Type.isString(json) ? JSON.parse(json) : json;
    };
    
    /**
     * data-mapping-value
     * @param {Object} json
     * @param {String} key
     * @param {Object} value
     */
    JSON_Util.setPath = function(json, key, value) {
        json = ( typeof json) === 'object' ? json : {};
        var keys = key.split(/-|\./g), 
            i = 0, 
            keyCount = keys.length, 
            jsonMemberTemp = json;
    
        for (; i < keyCount; i++) {
            if (keyCount - 1 === i) {
                jsonMemberTemp[keys[i]] = value;
            } else {
                jsonMemberTemp = jsonMemberTemp[keys[i]] = jsonMemberTemp[keys[i]] || {};
            }
        }
        return json;
    };
    
    //data-mapping-value
    JSON_Util.getByPath = function(json, path){
        if(ujs.Type.isUndefined(path)){
            path = json;
            json = window;
        }
        var val = null,
            keys = path.split(/-|\./g), 
            i = 0, 
            keyCount = keys.length, 
            jsonMemberTemp = json;
        
        if(json){
            for(; i<keyCount; i++){
                if(!jsonMemberTemp[keys[i]]){
                    return val;
                }
                jsonMemberTemp = jsonMemberTemp[keys[i]];
            }
            val = jsonMemberTemp;
        }
        return val;
    };  
    
    //----------------------------------------------------------------------------------------

    //TODO 兼容性代码.    
    ujs.extend(window.JSON, JSON_Util);
    
    //----------------------------------------------------------------------------------------
    
    ujs.define('json', 'ujs', function(){
        return JSON_Util;
    });
      
})(window);